/**
 * 
 */
package net.destroyer.game.tetris.gui;

import java.awt.Dimension;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JFrame;

import net.destroyer.game.tetris.core.Engine;
import net.destroyer.game.tetris.core.IEngine;
import net.destroyer.game.tetris.gui.control.ExitCommand;
import net.destroyer.game.tetris.gui.control.interf.IGuiCommand;
import net.destroyer.game.tetris.gui.menu.Menubar;
import net.destroyer.game.tetris.gui.status.StatusBar;
import net.destroyer.game.tetris.gui.status.StatusPanel;


/**
 * @author slizavit
 *
 */
public class MainWindow extends JFrame implements WindowListener {

	private Dimension dim = new Dimension(800,600);
	private Dimension gamewin = new Dimension(525,525);
	private Dimension status = new Dimension(250,550);
	private Dimension statusbar = new Dimension(800,20);
	
	private IEngine core;
	private Map<String, IGuiCommand> cmd;
	private State state;
	/**
	 * 
	 */
	private static final long serialVersionUID = 5437273800108336922L;

	public MainWindow() {
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.addWindowListener(this);
		this.state = State.OPEN;
		this.cmd = new HashMap<String, IGuiCommand>();
		this.cmd.put(ExitCommand.class.getName(), new ExitCommand(core, this));
		this.core = new Engine();
		//this.setAlwaysOnTop(true);
		this.setTitle("Tetris3D");
		this.setMinimumSize(dim);
		this.setResizable(false);
		StatusBar statusBar = new StatusBar(statusbar);
		getContentPane().add(statusBar, java.awt.BorderLayout.SOUTH);
		
		StatusPanel stat = new StatusPanel(status);
		getContentPane().add(stat, java.awt.BorderLayout.EAST);
		
		this.setJMenuBar(new Menubar(this));

		GameWindow u = new GameWindow(gamewin,core);
		getContentPane().add(u, java.awt.BorderLayout.WEST);
		
	}
	public void Run(){
		this.setVisible(true);
	}

	public State getStatus() {
		return this.state;
	}
	public void setStatus(State state) {
		this.state = state;
	}
	public IGuiCommand getCommand(String val){
		return cmd.get(val);
	}
	@Override
	public void windowActivated(WindowEvent e) {
		
	}
	@Override
	public void windowClosed(WindowEvent e) {
		
	}
	@Override
	public void windowClosing(WindowEvent e) {
		this.cmd.get(ExitCommand.class.getName()).execute();
	}
	@Override
	public void windowDeactivated(WindowEvent e) {
		
	}
	@Override
	public void windowDeiconified(WindowEvent e) {
		
	}
	@Override
	public void windowIconified(WindowEvent e) {
		
	}
	@Override
	public void windowOpened(WindowEvent e) {
		
	}
	
}
